package the_fourth_chapter;

/**
 * 矩阵转置
 * 
 * @author explorati
 *
 */
public class Matrix_2 {

	// 计算传入输入的转置矩阵
	public static int[][] transposition(int[][] m) {
		int[][] m1 = new int[m[0].length][m.length];
		for (int i = 0; i < m.length; i++) {
			for (int j = 0; j < m[0].length; j++) {
				m1[j][i] = m[i][j];
			}
		}
		return m1;
	}

	public static void main(String[] args) {
		int[][] m1 = new int[3][4];
		for (int i = 0; i < m1.length; i++) {
			for (int j = 0; j < m1[0].length; j++) {
				m1[i][j] = 10 * (i + 1) + (j + 1);
			}
		}

		System.out.println("输入的数组为：");
		for (int i = 0; i < m1.length; i++) {
			for (int j = 0; j < m1[0].length; j++) {
				System.out.print(m1[i][j] + "\t");
			}
			System.out.println();
		}

		System.out.println();

		int[][] m2 = transposition(m1);
		System.out.println("转置后的矩阵为：");
		for (int i = 0; i < m2.length; i++) {
			for (int j = 0; j < m2[0].length; j++) {
				System.out.print(m2[i][j] + "\t");
			}
			System.out.println();
		}
	}
}
